<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="sun.applet.resources.MsgAppletViewer_it"%>
<%@page import="utility.connections"%>
<%@page import="utility.formatData" %>
<%@page import="sun.text.resources.FormatData"%><html>
<script type="text/javascript" src="../js/immagini.js"></script>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<head>

<jsp:useBean id="clsConn" scope="session" class="utility.connections"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ELENCO DIPENDENTI</title>
</head>
<%! String codice=""; %>
<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>  
          <%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			String user = session.getAttribute("user").toString();
			String type = session.getAttribute("type").toString();
			String matr = session.getAttribute("matricola").toString();
			String nome = session.getAttribute("nome").toString();
			String cogn = session.getAttribute("cognome").toString();
			codice = request.getParameter("codice");
			}
		%>

        </tr>
     <tr>

   	</tr>
      <tr>
        <td class="style1"><p align="center"><input type="button" value="INDIETRO" onclick="javascript:back();"/></p></td>
        </tr>
      <tr>
        <td class="style1"><div align="center"><strong>Elenco dipendenti assegnati al gruppo  </strong></div></td>
        </tr>
      <tr>
        <td class="style1"><div align="center">
          <table width="100%" cellpadding="2" cellspacing="0" bordercolor="#000000" style="border:1px solid;">
            <tr>
              <td width="8%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >PROG.</div></td>
              <td width="17%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_dip.jsp?order=1&codice=<%=codice%>">MATRICOLA</a></div></td>
              <td width="21%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_dip.jsp?order=2&codice=<%=codice%>">COD. FISCALE</a></div></td>
              <td width="26%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_dip.jsp?order=3&codice=<%=codice%>">NOME</a></div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_dip.jsp?order=4&codice=<%=codice%>">COGNOME</a></div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_dip.jsp?order=5&codice=<%=codice%>">DATA INIZIO</a></div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_dip.jsp?order=6&codice=<%=codice%>">DATA FINE</a></div></td>
            </tr>
			
			

<%! String user, matricola, codicefiscale, nome, cognome,datainizio,datafine; 
	Connection conn;
	Statement  st;
	ResultSet  rs;
%>
<%
				
				user = session.getAttribute("user").toString().toLowerCase();
				conn=connections.getConnection();
				st=connections.getStatement();
				int order = Integer.parseInt(request.getParameter("order"));
				String qry="";
				String set="dipendente and gruppodilavoro="+codice;
				String sel="matricola,codicefiscale, nome, cognome,datainizio,datafine";
				switch(order)
				{
				case 1: qry = "select "+sel+" from personale,allocazione where matricola="+set+"order by matricola";     break; //ordine per matricola
				case 2: qry = "select "+sel+" from personale,allocazione where matricola="+set+"order by codicefiscale"; break;//ordine per codice fiscale
				case 3: qry = "select "+sel+" from personale,allocazione where matricola="+set+"order by nome";          break;//ordine per nome
				case 4: qry = "select "+sel+" from personale,allocazione where matricola="+set+"order by cognome";       break;//ordine per cognome
				case 5: qry = "select "+sel+" from personale,allocazione where matricola="+set+"order by datainizio";       break;//ordine per cognome
				case 6: qry = "select "+sel+" from personale,allocazione where matricola="+set+"order by datafine";       break;//ordine per cognome
				}
				System.out.println("la query "+qry);
				
				ResultSet rs = st.executeQuery(qry);
				int i=0;
				
				if(rs.isBeforeFirst()&&rs.isAfterLast())
				{
					//Avvisare che non ci sono record!!!!
				}
				else
				{
					while (rs.next())
					{
						matricola = rs.getString("matricola");
						codicefiscale = rs.getString("codicefiscale");
						nome=rs.getString("nome");
						cognome=rs.getString("cognome");
						datainizio=rs.getString("datainizio");
						datafine=rs.getString("datafine");
				
						String color;
	              		String bordercell;
	              		
	              		i++;
	              		
	              		if (i%2==0)
	              		{
	              			color ="\"#E0E0E0\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		else
	              		{
	              			color = "\"#EFFFEF\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		
	              		out.println("<tr>");
	              		out.println("<td align=\"right\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + i + "</td>"); //prog.
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + matricola + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + codicefiscale + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + nome + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + cognome + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + formatData.format(datainizio) + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + formatData.format(datafine) + "</td>");
	              		out.println("</tr>");
					}	
				}
				
				rs.close();
				st.close();
             %>
          </table>
        </div></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#000099" height="30"><div align="right" class="style4">ELENCO DIPENDENTI  </div></td>
  </tr>
</table>
</body>
</html>
